#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 505;
const int M = 5e4 + 5;

int n, m, k;
struct Node {
  int w, v;
};
vector<Node> a[N];
ll dp[2][M];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m >> k;
  rep(i, 1, n) {
    int v, w, c;
    cin >> v >> w >> c;
    a[c].push_back(Node{w, v});
  }
  rep(i, 1, n) {
    if (a[i].empty()) continue;
    rep(j, 0, m) dp[1][j] = -1e18;
    for (Node p : a[i]) {
      int w = p.w, v = p.v;
      per(j, m, v) {  // sel
        dp[1][j] = max(dp[1][j], dp[1][j - v] + w);
        dp[1][j] = max(dp[1][j], dp[0][j - v] + w);
      }
    }
    per(j, m, 0) dp[0][j] = max(dp[0][j], dp[1][j] + k);
  }
  cout << dp[0][m];
  return 0;
}